<template>


  <el-row>
    <el-col  :span="24">
      窗口挂号
    </el-col>
  </el-row>

  <el-row>
    <el-col  :span="24">
      <el-button @click="saveReqister" type="primary">挂号</el-button>
      <el-button type="primary">清空</el-button>
    </el-col>
  </el-row>
  <el-row>
    <el-col :span="24"><h2>基本信息</h2></el-col>
  </el-row>
  <table class="rt">
    <tr>
      <td>病例号</td>
      <td> <el-input disabled /></td>
      <td>姓名:</td>
      <td> <el-input v-model="onsite.realName"  /></td>
      <td>性别:</td>
      <td>
        <el-select v-model="onsite.gender">
          <el-option label="男" value="男" />
          <el-option label="女" value="女" />
        </el-select>
      </td>
    </tr>
    <tr>
      <td>年龄:</td>
      <td>
        <el-input v-model="onsite.age" style="width: 160px"  type="number"  />
        <el-select style="width: 60px" v-model="onsite.ageType"  placeholder="年龄">
          <el-option label="年" value="年" />
          <el-option label="天" value="天" />
        </el-select>

      </td>
      <td>出生年月:</td>
      <td><el-date-picker
          v-model="onsite.birthday"
          type="date"
          placeholder="Pick a day"
          value-format="YYYY-MM-DD"

      /></td>
      <td>身份证:</td>
      <td> <el-input v-model="onsite.cardNumber"></el-input></td>
    </tr>
    <tr>
      <td>家庭住址</td>
      <td colspan="5"><el-input v-model="onsite.homeAddress"></el-input></td>
    </tr>
  </table>

  <el-row>
    <el-col :span="24"><h2>挂号信息</h2></el-col>
  </el-row>
  <table class="rt">
    <tr>
      <td>结算类别</td>
      <td>
        <el-select v-model="onsite.settleCategoryId" >
          <el-option v-for="jie in information" :label="jie.settleName" :value="jie.id" />
        </el-select>
      </td>
      <td>看诊时间:</td>
      <td>
      <el-date-picker
          v-model="onsite.visitDate"
          type="datetime"
          disabled

      /></td>
      <td>午别:</td>
      <td>
        <el-select disabled v-model="onsite.noon">
          <el-option label="男" value="男" />
          <el-option label="女" value="女" />
        </el-select>
      </td>
    </tr>
    <tr>
      <td>挂号科室:</td>
      <td>
        <el-select  v-model="onsite.deptmentId">
          <el-option v-for="d in depList" :label="d.deptName" :value="d.id" />

        </el-select>

      </td>
      <td>号别:</td>
      <td>
        <el-select  v-model="onsite.registLevelId" @change="levelChange">
          <el-option v-for="r in regIsList" :label="r.registName" :value="r.id" />

        </el-select>
      </td>
      <td>看诊医生:</td>
      <td>
      <el-select @click="getVisitEmps" v-model="onsite.employeeId">
       <el-option v-for="de in de"  :label="de.realname" :value="de.id" />
      </el-select>
      </td>
    </tr>
    <tr>
      <td>初始号额:</td>
      <td><el-input disabled v-model="registQuota"></el-input></td>
      <td>已用号额:</td>
      <td><el-input></el-input></td>
      <td>病例本:</td>
      <td>
        <el-switch
            v-model="onsite.isBook"
            class="ml-2"
            style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
        />
      </td>
    </tr>
    <tr>
      <td>应收金额：</td>
      <td><el-input disabled v-model="onsite.registMoney"></el-input></td>
      <td>收费方式:</td>
      <td><el-select  v-model="onsite.registMethod">

        <el-option v-for="p in paymentList" :label="p.payment" :value="p.payment" />
      </el-select></td>
      <td colspan="2"></td>
    </tr>
  </table>
</template>

<script>

  let md = new Date();
  let year = md.getFullYear();
  let m = md.getMonth()+1;
  m = m<10?'0'+m:m;
  let r = md.getDate();
  r = r<10?'0'+r:r;
  let x = md.getHours();
  x = x<10?'0'+x:x;
  let f = md.getMinutes();
  f = f<10?'0'+f:f;
  let t = md.getSeconds();
  let y =year + '-' + m + '-' + r + '-' + x + '-' + f + '-' + t;

import { ElMessage } from 'element-plus'
export default {

  name: "onsite",
  data(){
   return {
     onsite: {visitDate:'',noon:new Date().getHours()<=12?"上午":"下午",isBook:true},
     information:[],
     depList:[],
     regIsList:[],
     employeeList:[],
     paymentList:[],
     de:[],
     delmark:2,
     registQuota:''
   }
  },
  methods:{
    saveReqister(){
      this.onsite.visitDate=y
      console.log(this.onsite)
      let str=this.$qs.stringify(this.onsite)
      this.$axios.get("http://localhost:8080/register/add?"+str).then((a)=>{
       let add=true
        if (add==a.data){
          ElMessage.success("添加成功")

        }else {
          ElMessage.error("添加失败")
        }


      })
    },
    getVisitEmps(){
      console.log(this.onsite.deptmentId)
      console.log(this.onsite.registLevelId)
      if (!(this.onsite.deptmentId&&this.onsite.registLevelId)){
        ElMessage.error('请选择挂号科室和号别')
      }else {
        this.$axios.get("http://localhost:8080/emp/Dlist?deptmentId="+this.onsite.deptmentId+"&registLevelId="+this.onsite.registLevelId).then((d)=>{

          this.de=d.data
          console.log(this.de)

        })
      }
    },
    levelChange(){
      for(let i in this.regIsList){
        if (this.regIsList[i].id==this.onsite.registLevelId){
          this.registQuota=this.regIsList[i].registQuota
          this.onsite.registMoney=this.regIsList[i].registFee
        }
      }
    }
  },
  created() {


    this.$axios.get("http://localhost:8080/set/list").then((res)=>{

      this.information=res.data
     console.log(this.information)



    })
    this.$axios.get("http://localhost:8080/dep/list").then((dep)=>{

      this.depList=dep.data
      console.log(this.depList)



    })
    this.$axios.get("http://localhost:8080/reg/list").then((reg)=>{

      this.regIsList=reg.data
      console.log(this.information)



    })
    this.$axios.get("http://localhost:8080/emp/list").then((ey)=>{

      this.employeeList=ey.data
      console.log(this.employeeList)



    })
    this.$axios.get("http://localhost:8080/payment/list").then((payment)=>{

      this.paymentList=payment.data
      console.log(this.information)



    })

  }
}
</script>

<style scoped>
*{
  font-size: 12px;
}
.el-row:nth-child(1){
  border-top: solid 1px lightgray;
  border-bottom: solid 1px lightgray;
  padding: 20px 0px;
}
.el-row{
  margin-top: 20px;
  margin-bottom: 20px;
}
.el-col{
  text-align: left;
}
.rt{
  background-color: white;
  width: 100%;
  text-align: left;
  color: #909399;
}
.rt td{
  padding: 10px;
}
.rt td:nth-child(odd){
  width: 100px;
  background-color: #FAFAFA;

}
</style>